package com.example.library_hy_advert.system;


import android.os.Environment;
import android.util.Log;

import com.blankj.utilcode.util.FileUtils;

import java.io.File;

public class Path {
    private static final String TAG = "Path";
    private static boolean isLog = true;
    //主目录
    private static String mainDir = "guideBoardAPP";

    //Crash目录
    private static String crashDir = "hive-crash";

    //缓存目录
    private static String cachePath = "cache";

    //线路缓存
    private static String linePath = "line";

    // 缓存目录 bottom
    private static String cachePathBottom = "cacheBottom";

    //资源目录
    private static String resourcePath = "resource";

    //数据库目录
    private static String databasePath = "database";

    //日志目录
    private static String logPath = "bus_log";

    private static String fromOnline = "online";

    private static String fromLocal = "local";

    //online
    private static String onlineAdvertPath = "onlineResource";
    //online 中部广告目录
    private static String onlineCenterAdvert = "advertCenter";
    //online 底部广告目录
    private static String onlineBottomAdvert = "advertBottom";
    //参数缓存存储目录
    private static String onlinePropertyCache = "property";
    //参数缓存存储目录
    private static String onlinePropertyBottomCache = "propertyBottom";
    //参数缓存存储目录2
    private static String onlineScreenCache = "screen";


    //local 中部广告目录
    private static String advertLocalCenter = "advertLocalCenter";

    //local 底部广告目录
    private static String advertLocalBottom = "advertLocalBottom";

    // apk 下载目录
    private static String apkPath = "apks";

    /***
     * 初始化公共路径
     */
    public static void init(){
        File rootDir = Environment.getExternalStorageDirectory();
        rootDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);

        File dir = new File(rootDir,Path.mainDir);
        boolean orExistsDir = FileUtils.createOrExistsDir(dir);
        mainDir = dir.getPath();
        d("主目录创建结果：" + orExistsDir);
        d("主目录：" + mainDir);

        dir = new File(mainDir,databasePath);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        databasePath = dir.getPath();
        d("数据库目录创建结果：" + orExistsDir);
        d("数据库目录：" + databasePath);

        dir = new File(mainDir,cachePath);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        cachePath = dir.getPath();
        d("缓存目录创建结果：" + orExistsDir);
        d("缓存目录：" + cachePath);

        dir = new File(mainDir,linePath);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        linePath = dir.getPath();
        d("线路目录创建结果：" + orExistsDir);
        d("线路目录：" + linePath);

        dir = new File(mainDir,cachePathBottom);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        cachePathBottom = dir.getPath();
        d("缓存Bottom目录创建结果：" + orExistsDir);
        d("缓存Bottom目录：" + cachePathBottom);

        dir = new File(mainDir,resourcePath);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        resourcePath = dir.getPath();
        d("资源目录创建结果：" + orExistsDir);
        d("资源目录：" + resourcePath);

        dir = new File(Environment.getExternalStorageDirectory(),logPath);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        logPath = dir.getPath();
        d("日志目录创建结果：" + orExistsDir);
        d("日志目录：" + logPath);

        dir = new File(dir,Path.crashDir);
        crashDir = dir.getPath();
        d("crash目录创建结果：不创建");
        d("crash目录：" + crashDir);

        dir = new File(resourcePath,onlineAdvertPath);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        onlineAdvertPath = dir.getPath();
        d("在线广告目录创建结果：" + orExistsDir);
        d("在线广告目录：" + dir);

        dir = new File(onlineAdvertPath, onlineCenterAdvert);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        onlineCenterAdvert = dir.getPath();
        d("在线中部广告目录创建结果：" + orExistsDir);
        d("在线中部广告目录：" + onlineCenterAdvert);

        dir = new File(onlineAdvertPath, onlineBottomAdvert);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        onlineBottomAdvert = dir.getPath();
        d("在线底部广告目录创建结果：" + orExistsDir);
        d("在线底部广告目录：" + onlineBottomAdvert);

        dir = new File(onlineAdvertPath, onlinePropertyCache);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        onlinePropertyCache = dir.getPath();
        d("在线广告参数目录创建结果：" + orExistsDir);
        d("在线广告参数目录：" + onlinePropertyCache);

        dir = new File(onlineAdvertPath, onlinePropertyBottomCache);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        onlinePropertyBottomCache = dir.getPath();
        d("在线底部广告参数目录创建结果：" + orExistsDir);
        d("在线底部广告参数目录：" + onlinePropertyBottomCache);

        dir = new File(onlineAdvertPath, onlineScreenCache);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        onlineScreenCache = dir.getPath();
        d("在线广告参数目录创建结果：" + orExistsDir);
        d("在线广告参数目录：" + onlineScreenCache);


        dir = new File(rootDir, advertLocalCenter);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        advertLocalCenter = dir.getPath();
        d("中部广告本地目录创建结果：" + orExistsDir);
        d("中部广告本地目录：" + advertLocalCenter);
        dir = new File(rootDir, advertLocalBottom);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        advertLocalBottom = dir.getPath();
        d("底部广告本地目录创建结果：" + orExistsDir);
        d("底部广告本地目录：" + advertLocalBottom);

        dir = new File(rootDir, apkPath);
        orExistsDir = FileUtils.createOrExistsDir(dir);
        apkPath = dir.getPath();
        d("apk下载目录创建结果：" + orExistsDir);
        d("apk下载目录：" + apkPath);
    }

    public static String getDatabasePath() {
        return databasePath;
    }

    public static String getResourcePath() {
        return resourcePath;
    }

    public static String getCachePath(){
        return cachePath;
    }

    public static String getLinePath(){
        return linePath;
    }

    public static String getCachePathBottom(){
        return cachePathBottom;
    }

    public static String getCrashDir() {
        return crashDir;
    }



    public static String getLogPath(){
        return logPath;
    }

    private static void d(String msg){
        if(isLog){
            Log.d(TAG, msg);
        }
    }

    public static String getOnlineAdvertPath() {
        return onlineAdvertPath;
    }
    public static String getOnlinePropertyCache() {
        return onlinePropertyCache;
    }
    public static String getOnlinePropertyBottomCache() {
        return onlinePropertyBottomCache;
    }
    public static String getOnlineScreenCache() {
        return onlineScreenCache;
    }
    public static String getAdvertCenterPath(){
        return onlineCenterAdvert;
    }
    public static String getAdvertBottomPath(){
        return onlineBottomAdvert;
    }

    public static String getAdvertLocalCenter() {
        return advertLocalCenter;
    }

    public static String getAdvertLocalBottom() {
        return advertLocalBottom;
    }
}